package com.oa.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.oa.bean.WorkDiary;
import com.oa.service.WorkDiaryService;

@Controller
public class WorkDiaryController {

	@Resource
	WorkDiaryService workDiaryService;
	
	@RequestMapping("addMyDiary")
	public String addMyDiary(WorkDiary diary,HttpSession session){
		Integer uid = (Integer) session.getAttribute("uid");
		diary.setWuser_id(uid);
		Integer result = workDiaryService.addWorkDiary(diary);
		if(result!=0){
			return "redirect:Template/mydiary.jsp";
		}
		return "";
	}
	@RequestMapping("lookMyDiary")
	@ResponseBody
	public Map<String,Object> lookMyDiary(Integer currentPage,HttpSession session){
		Integer uid = (Integer) session.getAttribute("uid");
		Map<String,Object> map = workDiaryService.getMyWorkDiary(uid, currentPage);
		
		return map;
	}
	
	@RequestMapping("lookDeptDiary")
	@ResponseBody
	public Map<String,Object> lookDeptDiary(Integer currentPage,HttpSession session){
		Integer dept_id = (Integer) session.getAttribute("dept_id");
		Map<String,Object> map = workDiaryService.getMyWorkDiary(dept_id, currentPage);
		
		return map;
	}
	
	@RequestMapping("replyStaffDiary")
	@ResponseBody
	public String replyStaffDiary(String reply_content,Integer wid,HttpSession session){
		System.out.println("reply_content="+reply_content+"wid"+wid);
		Integer uid = (Integer) session.getAttribute("uid");
		Map<String,Object> map = new HashMap<>();
		map.put("reply_content", reply_content);
		map.put("wid", wid);
		map.put("reply_uid", uid);
		String result = workDiaryService.replyDiary(map);
		return result;
	}
	
	@RequestMapping("getDiaryOne")
	@ResponseBody
	public WorkDiary getDiaryOne(Integer wid){
		System.out.println(wid);
		WorkDiary diary = workDiaryService.getDiaryById(wid);
		return diary;
	}
	
}
